package com.song.api.controller.files;

import com.song.api.config.MyServiceList;
import com.song.api.controller.files.fallbacks.FileFallbackFactor;
import com.song.grace.result.GraceJSONResult;
import com.song.pojo.bo.NewAdminBO;
import io.swagger.annotations.Api;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Api(value = "文件上传的Controller", tags = {"文件上传的Controller"})
@RequestMapping("fs")
@FeignClient(value = MyServiceList.SERVICE_FILES ,fallbackFactory = FileFallbackFactor.class)
public interface FileUploaderControllerApi {

    /**
     * 上传单个文件
     * @param userId
     * @param file
     * @return
     * @throws Exception
     */
    @PostMapping("uploadFace")
    public GraceJSONResult uploadFace(@RequestParam String userId, MultipartFile file) throws Exception;

    /**
     * 上传多个文件
     * @param userId
     * @param files
     * @return
     * @throws Exception
     */
    @PostMapping("uploadSomeFiles")
    public GraceJSONResult uploadSomeFiles(@RequestParam String userId, MultipartFile[] files) throws Exception;

    /**
     * 文件上传保存MongoDB的GridFS中
     *
     * @param newAdminBO
     * @return
     * @throws Exception
     */
    @PostMapping("uploadToGridFS")
    public GraceJSONResult uploadToGridFS(@RequestBody NewAdminBO newAdminBO) throws Exception;

    /**
     * 从gridFS中读取文件
     *
     * @param faceId
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @GetMapping("readInGridFS")
    public void readInGridFS(String faceId,
                             @RequestParam HttpServletRequest request,
                             @RequestParam HttpServletResponse response) throws Exception;

    /**
     * 从gridFS中读取文件，并返回base64数据
     *
     * @param faceId
     * @return
     * @throws Exception
     */
    @GetMapping("readFace64InGridFS")
    public GraceJSONResult readFace64InGridFS(String faceId);

}


